/**** COMMON ****/
var b_gaid="UA-12420642-2";

	//attempt to load ga library
	try{
		if(!_gaq) {
			var $B_gaq = _gaq || [];
			$B_gaq.push(['_setAccount', b_gaid]);
			
			(function() {
				var $B_ga = document.createElement('script'); $B_ga.type = 'text/javascript'; $B_ga.async = true;
				$B_ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
				var $B_s = document.getElementsByTagName('script')[0]; $B_s.parentNode.insertBefore($B_ga, $B_s);
			})();
		} else {
			var $B_gaq = _gaq;
		}
	} catch(e) { /*ignore*/ }

/**** END COMMON ****/

//send ga call
try{
	$B_gaq.push(['_setAccount', b_gaid])
	$B_gaq.push(['_trackEvent','TT-Auto','Display Overlay']);
	$B_gaq.push(['_setAccount', 'UA-20455078-4']);
} catch(e) { /*ignore*/ }
		
if(!divObjAlreadyExists){
	/*
		buildCss() - apply css properties for the overlay
	*/
	function buildCss(){
		var styleElement=document.createElement("style");
		var ttHeader=$('div[class="header"]');
		var divLeft=parseInt($(ttHeader).css('left')) + 1 + parseInt($(ttHeader).css('width'));
		(isNaN(divLeft)) ? divLeft="761" : divLeft=divLeft;
		styleElement.type="text/css";
		styleElement.innerHTML=".gov{position:absolute;left:"+divLeft+"px;top:61px;width:125px;z-index:-1;border-style:solid;border-width:1xp;border-color:#DCAA29;color:white;z-index:100;background:rgb(0,0,0);background:rgba(0,0,0,1);padding:10px;font-size:12px;}a:visited{color:#F0F0F0;}a:link{color:#F0F0F0;}.hideGov{position:absolute;left:"+divLeft+"px;top:61px;width:125px;z-index:0;visibility:hidden;}";
		document.getElementsByTagName("head")[0].appendChild(styleElement);
	}
	/*
		appendDiv() - the div that will hold all of the custom content created in this file
		*	pv_divObj - existing div the new div will be appended to
		*	pv_newDivName - name/id to apply to new div
	*/
	function appendDiv(pv_divObj,pv_newDivName){
		var newDiv=document.createElement('div');
		newDiv.setAttribute("class","gov");
		newDiv.setAttribute("id",pv_newDivName);
		pv_divObj.appendChild(newDiv);
	}
	/*
		appendLinks() - appends the custom links to the new div created in appendDiv()
		*	pv_divObj - id of div to append links/content to
		*	pv_linkText - text that will be displayed to user as actual link/alt/title text
		*	pv_scriptType - if loading auto-[name].js script, provide "auto-[name]",
				if creating a "real" link to another page, send entire url (http://www.example.com/page.html)
		*	pv_notScript - pass as true if passing full url into pv_scriptType.  otherwise leave blank
	*/
	function appendLinks(pv_linkText,pv_scriptType,pv_notScript){
        var settingsDropdown=$("#settings .dropdown");
		var newLi=document.createElement('li');
		newLi.setAttribute('title',pv_linkText);
		newLi.setAttribute('alt',pv_linkText);
		
        if(pv_notScript) { //if passing in a "real" link, set href to url and target="_blank"
			newLi.setAttribute('href',pv_scriptType);
			newLi.setAttribute('target','_blank');
		} else { //load the requested script file
            newLi.setAttribute('onclick','loadScript("'+pv_scriptType+'");');
            newLi.setAttribute('id',pv_linkText.replace(" ",""));
            newLi.setAttribute('href','javascript:void(0)');
        }
        newLi.setAttribute('class','option');

		newLi.innerHTML=pv_linkText;
		settingsDropdown.append(newLi);
	}
}
var divObj=document.getElementById("ttLinksDiv"); //attempt to get custom div
if(!divObj){ //if div does not exist, create it
	buildCss();
	var mainDiv=document.getElementById("scene"); //get parent div to append new div to
	appendDiv(mainDiv,"ttLinksDiv");
	var divObj=document.getElementById("ttLinksDiv"); //grab the new div so we can work with it going forward
	divObj.setAttribute("class","hideGov"); //set div to hidden css class
} else {
	var divObjAlreadyExists=true; //note that the div has already been crated so we don't create it again
	divObj.setAttribute("class","hideGov"); //set div to hidden css class
}
if(!divObjAlreadyExists){ //if the div was just created above, build out the contents (links)
	//create local function that can be referenced onclick by the links added using appendLinks()
	var appendScript=document.createElement('script');
	appendScript.setAttribute('type','text/javascript');
	appendScript.innerHTML='function loadScript(pv_scriptType){var myScript="http://bcj19-tt.googlecode.com/svn/trunk/"+pv_scriptType+".js";$.getScript(myScript)};';
	mainDiv.appendChild(appendScript);
	
	//append the auto-[name] links
	appendLinks('Auto-Awesome','auto-awesome');
	appendLinks('Auto-DJ','auto-dj');
    $("div.settings-button").css("background-color","#0000FF");
}